package com.example.bzh.gamecat.ui.society;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.bzh.gamecat.bean.AdvertListBean;

import java.util.List;

/**
 * Created by Administrator on 2016/7/31.
 */
public class ViewPagerAdapter extends PagerAdapter {

    private List<AdvertListBean>mList;
    private Context mContext;

    public ViewPagerAdapter() {
    }

    public ViewPagerAdapter(List<AdvertListBean> imgurls, Context context) {
        this.mList = imgurls;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView iv = new ImageView(container.getContext());
        iv.setScaleType(ImageView.ScaleType.FIT_XY);
        String imgUrl = mList.get(position%mList.size()).getImgUrl();
        Glide.with(mContext).load(imgUrl).into(iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("TAG","AAAAAAAAAA"+mList.get(position%mList.size()).getJumpUrl());
                Intent intent = new Intent(mContext,SecondActivity.class);
                intent.putExtra("weburl",mList.get(position%mList.size()).getJumpUrl());
                mContext.startActivity(intent);
            }
        });
        container.addView(iv);
        return iv;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((ImageView) object);
    }
}
